package com.besall.allbase.bluetooth.service.Protocol;

import static com.besall.allbase.bluetooth.service.Protocol.ProtocolConstants.*;

import java.io.File;
import com.besall.allbase.common.utils.CacheManager;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.bes.bessdk.BesSdkConstants;
import com.bes.bessdk.utils.ArrayUtil;
import com.bes.bessdk.utils.SPHelper;
import com.bes.sdk.message.Constants;
import com.bes.sdk.utils.SettingsJsonUtils;
import com.besall.allbase.common.utils.FileUtils;
import com.besall.allbase.view.activity.chipstoollevel4.protocol.DevelopParams.CustomAsyncTask;
import com.besall.allbase.view.activity.chipstoollevel4.protocol.ProtocolPresenter;

import android.content.Context;
import android.util.Log;

import bb.lanxing.util.CommonUtil;

public class ProtocolCMD {
    public static final String TAG = "ProtocolCMD";
    private static Context mContext;
    public static String recevieMsg = "";
    public static String tempData = "";
    public static int time = 0;
    public static int state = RESULT_DEFAULT;
    public static byte[] dataLen = new byte[2];
    public static byte[] totalCount = new byte[2];
    public static int totalCounts = 0;//总包数
    public static int totalLen = 0;//数据总长度
    public static byte[] mpkgData = new byte[Constants.GENERAL_PROTOCOL_PKG_MAX_LEN];
    public static int tempResult = 0;
    public static int PKGS = 0;
    public static ArrayList<String> countsList = new ArrayList<>();
    public static int size = 0;
    public static int sleepLogDump = 0;
    public static String cacheSleepLog = "";
    public static String mFileName = "";
    public static String logName = "";
    public static byte[] crc = new byte[1];
    public static int logStatus = RESULT_DEFAULT;
    public static List<byte[]> singlePacket = new ArrayList<>();
    public static byte[] finalData = new byte[100];
    public static byte[] data = new byte[Constants.GENERAL_PROTOCOL_PKG_MAX_LEN+4];
    private static int mSysId = 0;
    private static int mReadType = -1;
    private static List<String> mDelList = new ArrayList<>();

    public static int receiveData(byte[] data){
        size += data.length;
        CacheManager<ProtocolCMD> cacheManager = new CacheManager<>();
        ProtocolCMD mObject = new ProtocolCMD();
        cacheManager.cacheObject(mObject);
        ProtocolCMD cacheOb = cacheManager.getCachedObject();
        if (size > 1000){
            Log.i(TAG, "run: clearCache");
            size = 0;
            cacheManager.clearCache();
        }

        int result = 0;
        if (sleepLogDump == 1){
            Log.i(TAG, "receiveData: saveSleepLog");
            saveSleepLog(data);
            result = RECEIVE_SLEEP_LOG_STATUS;
            return result;
        }
        if (data[0] == 0x7f){
            Log.i(TAG, "MutiPackage: 7f");
            result = anlyMutiPackage(data);
            return result;
        }
        if ((data[0] & 0xff) == 0x88 && (data[1] & 0xff) == 0x0e){
            Log.i(TAG, "88 0e");
            result = singlePackage(data);
            return result;
        }
        if ((data[0] & 0xff) == 0x88 && (data[1] & 0xff) == 0x8b){
            Log.i(TAG, "88 8b");
            result = algoLogData(data);
            return result;
        } if ((data[0] & 0xff) == 0x81 && (data[1] & 0xff) == 0xAC && (data[2] & 0xff) == 0x09 && (data[3] & 0xff) == 0x00 && (data[4] & 0xff) == 0x80){
//            && (data[5] & 0xff) == 0x0E && (data[6] & 0xff) == 0x01)
            Log.i(TAG, "receiveData: recive find watch");
            result = RECIVE_FIND_WATCH_ARK;
            return result;
        } else {
            saveDumpLog(data);
        }

        Log.i(TAG, "receiveData: result" + result);
        return result;
    }

    public static int singlePackage(byte[] data){
        if ((data[0] & 0xff) == 0x88 && (data[1] & 0xff) == 0x0e){
            int logLen = data.length - 4;
            byte[] LogLen = ArrayUtil.intToBytes2(logLen);
            mpkgData = new byte[logLen];
            System.arraycopy(data, 4, mpkgData, 0, logLen);
            byte[] ret = ArrayUtil.byteMerger(LogLen, mpkgData);
            recevieMsg = ArrayUtil.toHex(ret);
            Log.i(TAG, "singlePackage: " + recevieMsg);
            state = RESULT_LOG_NAME;
            return state;
        }
        return state;
    }

    public static int algoLogData(byte[] data){
        saveDumpLog(data);
        return RECIVE_ALGO_LOG;
    }

    public static int anlyMutiPackage(byte[] data){
        if (data[0] == 0x7f) {
            if (data[2] == 0x00 && (data[8] & 0xff) == 0x88 && (data[9] & 0xff) == 0x0e){
                tempResult = RESULT_LOG_NAME;
                if (data[2] == 0x00 && data[3] == 0x00) {
                    totalCount[0] = data[4];
                    totalCount[1] = data[5];
                    dataLen[0] = data[10];
                    dataLen[1] = data[11];
                    totalCounts = ArrayUtil.byte2int(totalCount);//总包数
                    totalLen = ArrayUtil.byte2int(dataLen);//数据总长度
                    Log.i(TAG, "totalCounts: " + totalCounts);
                    Log.i(TAG, "totalLen: " + totalLen);
                }
            }
            if (data[2] == 0x00 && (data[8] & 0xff) == 0x88 && (data[9] & 0xff) == 0x0f){
                saveOriginLog(data);
                tempResult = RESULT_LOG_FILE;
                state = RECIVE_LOG_FILE;
                if (data[2] == 0x00 && data[3] == 0x00) {
                    totalCount[0] = data[4];
                    totalCount[1] = data[5];
                    dataLen[0] = data[10];
                    dataLen[1] = data[11];
                    totalCounts = ArrayUtil.byte2int(totalCount);//总包数
                    totalLen = ArrayUtil.byte2int(dataLen);//数据总长度
                    Log.i(TAG, "totalCounts: " + totalCounts);
                    Log.i(TAG, "totalLen: " + totalLen);
                }
            }

            byte[] curCount = {data[2],data[3]};
            String count = String.valueOf(ArrayUtil.byte2int(curCount));
            if (!countsList.contains(count)){
                Log.i(TAG, "anlyMutiPackage: " + count);
                if (data[2] == 0x00 && data[3] == 0x00){
                    time = 0;
                    mpkgData = new byte[Constants.GENERAL_PROTOCOL_PKG_MAX_LEN-8];
                    System.arraycopy(data, 12, mpkgData, 0, Constants.GENERAL_PROTOCOL_PKG_MAX_LEN-8);
                    tempData = tempData + ArrayUtil.toHex(mpkgData);
                    countsList.add(count);
                    time++;
                } else if (time < (totalCounts - 1) && time > 0) {
                    mpkgData = new byte[Constants.GENERAL_PROTOCOL_PKG_MAX_LEN];
                    System.arraycopy(data, 4, mpkgData, 0, data.length - 4);
                    tempData = tempData + ArrayUtil.toHex(mpkgData);
                    countsList.add(count);
                    time++;
                } else if (time == totalCounts - 1) {
                    Log.i(TAG, "timeCounts: " + time);
                    Log.i(TAG, "anlyMutiPackage: last"  + ArrayUtil.toHex(data));
                    mpkgData = new byte[data.length - 4];
                    System.arraycopy(data, 4, mpkgData, 0, data.length - 4);
                    tempData = tempData + ArrayUtil.toHex(mpkgData);
                    recevieMsg = ArrayUtil.toHex(dataLen) + tempData;

                    state = tempResult;
                    countsList.add(count);
                    return state;
                }
            }
            Log.i(TAG, "times: " + time + countsList.size());
        }
        return state;
    }

    public static int anlyFileNameMutiPackage(byte[] data){
        if ((data[0] & 0xff) == 0x09 && (data[1] & 0xff) == 0x02){
            Log.i(TAG, "checkPubkey: "+ArrayUtil.toHex(data));
            byte[] pkglen = new byte[2];
            java.lang.System.arraycopy(data, 2, pkglen,0,2);
            int pkgL = ArrayUtil.byte2int(pkglen);
            Log.i(TAG, "checkPubkey: "+pkgL);

            byte[] pkgData = new byte[pkgL - 4];
            java.lang.System.arraycopy(data, 4, pkgData, 0, pkgL - 4);
            recevieMsg = ArrayUtil.toHex(pkgData);
            state = RESULT_LOG_NAME;
            return state;
        } else if (data[0] == 0x7f) {
            if (data[2] == 0x00 && (data[8] & 0xff) == 0x88 && (data[9] & 0xff) == 0x0e){
                crc[0] = data[1];
            }
            if (data[1] == crc[0]){
                if ((data[8] & 0xff) == 0x88 && (data[9] & 0xff) == 0x0e) {
                    totalCount[0] = data[4];
                    totalCount[1] = data[5];
                    dataLen[0] = data[10];
                    dataLen[1] = data[11];
                    totalCounts = ArrayUtil.byte2int(totalCount);//总包数
                    totalLen = ArrayUtil.byte2int(dataLen);//数据总长度
                    Log.i(TAG, "totalCounts: " + totalCounts);
                    Log.i(TAG, "totalLen: " + totalLen);
                    mpkgData = new byte[Constants.GENERAL_PROTOCOL_PKG_MAX_LEN-8];
                    java.lang.System.arraycopy(data, 12, mpkgData, 0, Constants.GENERAL_PROTOCOL_PKG_MAX_LEN-8);
                    tempData = tempData + ArrayUtil.toHex(mpkgData);
                    time++;
                } else if (time < (totalCounts - 1) && time > 0) {
                    mpkgData = new byte[Constants.GENERAL_PROTOCOL_PKG_MAX_LEN];
                    java.lang.System.arraycopy(data, 4, mpkgData, 0, Constants.GENERAL_PROTOCOL_PKG_MAX_LEN);
                    tempData = tempData + ArrayUtil.toHex(mpkgData);
                    time++;
                } else if (time == totalCounts - 1) {
                    Log.i(TAG, "timeCounts: " + time);
                    mpkgData = new byte[totalLen - Constants.GENERAL_PROTOCOL_PKG_MAX_LEN - 8 - Constants.GENERAL_PROTOCOL_PKG_MAX_LEN * (totalCounts - 2)];
                    java.lang.System.arraycopy(data, 4, mpkgData, 0, totalLen - Constants.GENERAL_PROTOCOL_PKG_MAX_LEN - 8 - Constants.GENERAL_PROTOCOL_PKG_MAX_LEN * (totalCounts - 2));
                    tempData = tempData + ArrayUtil.toHex(mpkgData);
                    recevieMsg = ArrayUtil.toHex(dataLen) + tempData;
                    state = RESULT_LOG_NAME;
                    return state;
                }
                Log.i(TAG, "times: " + time);
            }

        }
        return state;
    }

    public int anlyLogFile(byte[] data){
        if (data[0] == 0x7f && (data[8] & 0xff) == 0x88 && (data[9] & 0xff) == 0x0f) {
            totalCount[0] = data[4];
            totalCount[1] = data[5];
            dataLen[0] = data[10];
            dataLen[1] = data[11];
            totalCounts = ArrayUtil.byte2int(totalCount);//总包数
            totalLen = ArrayUtil.byte2int(dataLen);//数据总长度
            Log.i(TAG, "totalCounts: " + totalCounts);
            Log.i(TAG, "totalLen: " + totalLen);
            mpkgData = new byte[Constants.GENERAL_PROTOCOL_PKG_MAX_LEN-8];
            java.lang.System.arraycopy(data, 12, mpkgData,0,Constants.GENERAL_PROTOCOL_PKG_MAX_LEN-8);
            tempData = tempData + ArrayUtil.toHex(mpkgData);
            time ++;
        } else if (time < (totalCounts - 1) && time > 0) {
            mpkgData = new byte[Constants.GENERAL_PROTOCOL_PKG_MAX_LEN];
            java.lang.System.arraycopy(data, 4, mpkgData,0,Constants.GENERAL_PROTOCOL_PKG_MAX_LEN);
            tempData = tempData + ArrayUtil.toHex(mpkgData);
            time ++;
        } else if (time == totalCounts - 1){
            Log.i(TAG, "timeCounts: " + time);
            mpkgData = new byte[totalLen - Constants.GENERAL_PROTOCOL_PKG_MAX_LEN - 8 - Constants.GENERAL_PROTOCOL_PKG_MAX_LEN * (totalCounts - 2)];
            java.lang.System.arraycopy(data, 4, mpkgData,0,totalLen - Constants.GENERAL_PROTOCOL_PKG_MAX_LEN -8 - Constants.GENERAL_PROTOCOL_PKG_MAX_LEN * (totalCounts - 2));
            tempData = tempData + ArrayUtil.toHex(mpkgData);
            recevieMsg = ArrayUtil.toHex(dataLen) + tempData;
            logStatus = RESULT_LOG_FILE;
            return logStatus;
        }
        return logStatus;
    }

    public static void clearTemp(){
        Log.i(TAG, "clearTemp: ");
        tempData = "";
        state = RESULT_DEFAULT;
        time = 0;
        logStatus = RESULT_DEFAULT;
        countsList.clear();
        recevieMsg = "";
        sleepLogDump = 0;
    }

    public static void saveLog(){
        byte[] data = ArrayUtil.toBytes(tempData);
        String ret = ArrayUtil.toASCII(data);
        FileUtils.writeTOFile(ret, "LogOut", mFileName, "txt");
    }

    public static void saveOriginLog(byte[] data){
        String ret = ArrayUtil.toHex(data);
        FileUtils.writeTOFile(ret, "OriginData", mFileName, "txt");
    }

    public static void saveDumpLog(byte[] data){
        SimpleDateFormat format = new SimpleDateFormat("yyyy:MM:dd:HH:mm:ss");
        Date curD = new Date(java.lang.System.currentTimeMillis());
        String timeTag = format.format(curD) ;
        String ret = timeTag +":  " + ArrayUtil.toHex(data) + "\n";
        FileUtils.writeTOFile(ret, "DumpLog", logName, "txt");
    }
    public static void saveSleepLog(byte[] data){
        SimpleDateFormat format = new SimpleDateFormat("yyyy:MM:dd:HH:mm:ss");
        Date curD = new Date(java.lang.System.currentTimeMillis());
        String timeTag = format.format(curD) ;
        String ret = timeTag +":  " + ArrayUtil.toHex(data) + "\n";
        cacheSleepLog = cacheSleepLog + ret;
        Log.i(TAG, "saveSleepLog: " + cacheSleepLog);
        if (cacheSleepLog.length() > 1024){
            Log.i(TAG, "saveSleepLog: writeToFile");
            FileUtils.writeTOFile(cacheSleepLog, "SleepDumpLog", logName, "txt");
            cacheSleepLog = "";
        }
    }
    public static String getFileName(){
        return recevieMsg;
    }

    public static byte[] infomation(int id, byte[] params){
        byte[] data = new byte[100];
        if (id == INFO_Get_personal_information) {
            byte[] getPersonInfo = new byte[]{0x00, 0x01, 0x04, 0x00};
            data = getPersonInfo;
        } else if (id == INFO_Get_Device_Time) {
            byte[] getDeviceTime = new byte[]{0x00,0x06,0x04,0x00};
            data = getDeviceTime;
        }else if (id == INFO_Get_Battery_level){
            byte[] getBatteryLevel = new byte[]{0x00,0x08,0x04,0x00};
            data = getBatteryLevel;
        } else if (id == INFO_Get_device_worn_status) {
            byte[] getDeviceWarnStatus = new byte[]{0x00,0x0A,0x04,0x00};
            data = getDeviceWarnStatus;
        } else if (id == INFO_Get_device_charge_status) {
            byte[] getDeviceChargeStatus = new byte[]{0x00,0x0B,0x04,0x00};
            data = getDeviceChargeStatus;
        }else if (id == INFO_Get_lift_wrist_to_view_setting_old) {
            byte[] getLiftOld = new byte[]{0x00,0x0D,0x04,0x00};
            data = getLiftOld;
        }else if (id == INFO_Get_lift_wrist_to_view_setting_new) {
            byte[] getLiftNew = new byte[]{0x00,0x0D,0x04,0x00};
            data = getLiftNew;
        }else if (id == INFO_Get_serial_number) {
            byte[] getSerialNum = new byte[]{0x00,0x0E,0x04,0x00};
            data = getSerialNum;
        }else if (id == INFO_Get_temp_params) {
            byte[] getTempParams = new byte[]{0x00,0x20,0x04,0x00};
            data = getTempParams;
        }else if (id == INFO_Get_distance_unit) {
            byte[] getDistanceUnit = new byte[]{0x00,0x22,0x04,0x00};
            data = getDistanceUnit;
        }else if (id == INFO_Get_mac_address) {
            byte[] getMac = new byte[]{0x00,0x23,0x04,0x00};
            data = getMac;
        }else if (id == INFO_Get_firmware_version) {
            byte[] getFirmwareV = new byte[]{0x00,0x24,0x04,0x00};
            data = getFirmwareV;
        }else if (id == INFO_Get_the_automatic_heart_rate_interval) {
            byte[] getAutoHeartRate = new byte[]{0x00,0x25,0x04,0x00};
            data = getAutoHeartRate;
        }else if (id == INFO_Get_sound_volume) {
            byte[] getSoundValume = new byte[]{0x00,0x27,0x04,0x00};
            data = getSoundValume;
        }else if (id == INFO_Get_Phone_book) {
            byte[] getPhoneBook = new byte[]{0x00,0x28,0x04,0x00};
            data = getPhoneBook;
        }else if (id == INFO_Get_watch_size) {
            byte[] getWatchSize = new byte[]{0x00,0x29,0x04,0x00};
            data = getWatchSize;
        }else if (id == INFO_get_Amazon_mic_test_volume) {
            byte[] getAmazonoMicValume = new byte[]{0x00, (byte) 0xB1,0x04,0x00};
            data = getAmazonoMicValume;
        }else if (id == INFO_config_weather_control_info) {
            byte[] weatherConfig = new byte[]{0x00, (byte) 0xA9,0x14,0x00};
            data = weatherConfig;
        }else if (id == INFO_switch_and_get_broadcast_name_and_mac_address_of_BT) {
            byte[] switchBt = new byte[]{0x00, (byte) 0xAA,0x06,0x00};
            data = switchBt;
        }else if (id == INFO_Unbind_BT) {
            byte[] unbindBt = new byte[]{0x00, (byte) 0xAB,0x05,0x00};
            data = unbindBt;
        } else if (id == INFO_Set_personal_information) {
            byte[] setPersonInfo = new byte[]{0x00, (byte) 0x81,0x0A,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setPersonInfo, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_Set_Time__Format) {
            byte[] setPersonInfo = new byte[]{0x00, (byte) 0x82,0x05,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setPersonInfo, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_Set_Device_mode){
            byte[] setDeviceMode = new byte[]{0x00, (byte) 0x85,0x05,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setDeviceMode, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_Set_Pairing_phone_type){
            byte[] phonePairType = new byte[]{0x00, (byte) 0x86,0x05,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(phonePairType, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_Set_Device_Time) {
            Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"),
                    Locale.getDefault());
            Date currentLocalTime = calendar.getTime();
            //initView: +0800
            DateFormat date = new SimpleDateFormat("Z");
            String localTime = date.format(currentLocalTime);
            Log.i(TAG, "initView: " + localTime);
            byte[] gmt = localTime.getBytes();
            byte[] gmtSymbol = new byte[1];
            gmtSymbol[0] = gmt[0];
            Pattern pattern = Pattern.compile("\\D"); // \\D 表示非数字字符
            Matcher matcher = pattern.matcher(localTime);
            String gmtN = matcher.replaceAll("");
            String[] T = ArrayUtil.stringToStringArray(gmtN,2);
            byte[] gmtTime = new byte[T.length];
            int a = 0 ;
            for (int i = 0; i < T.length; i++) {
                a = Integer.parseInt(T[i]);
                gmtTime[i] = ArrayUtil.intToBytes3(a)[0];
            }
            SimpleDateFormat format = new SimpleDateFormat("yyyy:MM:dd:HH:mm:ss");
            Date curD = new Date(java.lang.System.currentTimeMillis());
            String logtime = format.format(curD);
            String curT = logtime.replace(":", "");
            String[] d = ArrayUtil.stringToStringArray(curT,2);
            byte[] time = new byte[d.length];
            int t = 0 ;
            for (int i = 0; i < d.length; i++) {
                t = Integer.parseInt(d[i]);
                time[i] = ArrayUtil.intToBytes3(t)[0];
            }
            Log.i(TAG, "initView: curT" + logtime);
            Log.i(TAG, "initView: " + ArrayUtil.toHex(time));
            byte[] gmtInfo = ArrayUtil.byteMerger(gmtSymbol, gmtTime);
            byte[] finalTime = ArrayUtil.byteMerger(time, gmtInfo);
            byte[] setDeviceTime = new byte[]{0x00,(byte) 0x87,0x0E,0x00,};
            data = ArrayUtil.byteMerger(setDeviceTime, finalTime);
        } else if (id == INFO_Set_Time_Zone_time) {
            Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"),
                    Locale.getDefault());
            Date currentLocalTime = calendar.getTime();
            //initView: +0800
            DateFormat date = new SimpleDateFormat("Z");
            String localTime = date.format(currentLocalTime);
            Log.i(TAG, "initView: " + localTime);
            byte[] gmt = localTime.getBytes();
            byte[] gmtSymbol = new byte[1];
            //协议:印度客户0x2c 表示”-“
            if (gmt[0] == 0x2d){
                gmtSymbol[0] = 0x2c;
            } else {
                gmtSymbol[0] = gmt[0];
            }

            Pattern pattern = Pattern.compile("\\D"); // \\D 表示非数字字符
            Matcher matcher = pattern.matcher(localTime);
            String gmtN = matcher.replaceAll("");
            String[] T = ArrayUtil.stringToStringArray(gmtN,2);
            byte[] gmtTime = new byte[T.length];
            int a = 0 ;
            for (int i = 0; i < T.length; i++) {
                a = Integer.parseInt(T[i]);
                gmtTime[i] = ArrayUtil.intToBytes3(a)[0];
            }
            byte[] gmtZone = new byte[1];
            gmtZone[0] = gmtTime[0];
            byte[] gmtInfo = ArrayUtil.byteMerger(gmtSymbol, gmtTime);
            byte[] ret = ArrayUtil.byteMerger(gmtZone, gmtInfo);
            Log.i(TAG, "GMT: " + ArrayUtil.toHex(ret));
            byte[] setTimeZonetime = new byte[]{0x00,(byte) 0x89,0x08,0x00};
            data = ArrayUtil.byteMerger(setTimeZonetime, ret);
        } else if (id == INFO_Set_band_screens) {
            byte[] setBandScreens = new byte[]{0x00,(byte) 0x8B,0x08,0x00,   0x06,0x2c,0x07,0x00};
            data = setBandScreens;
        } else if (id == INFO_Set_Hand_preference) {
            byte[] setHand = new byte[]{0x00, (byte) 0x8C,0x05,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setHand, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_Set_lift_wrist_to_view_setting_old) {
            byte[] setLWOld = new byte[]{0x00, (byte) 0x8D,0x05,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setLWOld, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_Set_lift_wrist_to_view_setting_new) {
            byte[] setLWNew = new byte[]{0x00, (byte) 0x8D,0x09,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setLWNew, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_Set_serial_number) {
            byte[] setSerial = new byte[]{0x00, (byte) 0x8E,0x0A,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setSerial, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_Set_connection_key) {
            byte[] setConnectKey = new byte[]{0x00, (byte) 0x8f,0x0C,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setConnectKey, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_Set_the_time_interval_of_the_probe_function) {
            byte[] setProbInv = new byte[]{0x00, (byte) 0x90,0x05,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setProbInv, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_Set_temperature_display_type) {
            byte[] setProbInv = new byte[]{0x00, (byte) 0xA0,0x05,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setProbInv, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_Set_Device_auto_monitor_Temp) {
            byte[] setAMTInval= new byte[]{0x00, (byte) 0xA1,0x05,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setAMTInval, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_Set_distance_display_unit) {
            byte[] setUnit= new byte[]{0x00, (byte) 0xA2,0x05,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setUnit, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_set_sound_volume) {
            byte[] setVolume= new byte[]{0x00, (byte) 0xA7,0x05,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setVolume, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_set_Phone_book) {

        } else if (id == INFO_set_Amazon_Alexa_state) {
            byte[] setAlexaState = new byte[]{0x00, (byte) 0xAD,0x05,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setAlexaState, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_set_Amazon_Alexa_Status) {
            byte[] setAlexaState = new byte[]{0x00, (byte) 0xAE,0x05,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setAlexaState, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_Set_screen_brightness) {
            byte[] setBrightness = new byte[]{0x01, (byte) 0xAF,0x0A,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setBrightness, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        } else if (id == INFO_set_Amazon_mic_test) {
            byte[] setMic = new byte[]{0x00, (byte) 0xB0,0x05,0x00};
            byte[] ret = new byte[4 + params.length];
            System.arraycopy(setMic, 0, ret, 0, 4);
            System.arraycopy(params, 0, ret, 4, params.length);
            data = ret;
        }

        Log.i(TAG, "infomation: " + ArrayUtil.toHex(data));
        return data;
    }

    public static byte[] fitnessData(int id, byte[] params){
        byte[] data = new byte[100];
        if (id == FIT_GET_FITNESS_DAILY_VALUE){
            byte[] dailyValue = new byte[]{0x01,0x00,0x05,0x00};
            data = ArrayUtil.byteMerger(dailyValue, params);
        } else if (id == FIT_GET_ECG_HISTROY_DATA) {
            byte[] ecgHistroy = new byte[]{0x01,0x01,0x07,0x00};
            SimpleDateFormat format = new SimpleDateFormat("HH");
            Date curD = new Date(java.lang.System.currentTimeMillis());
            String logtime = format.format(curD);
            byte[] curT = ArrayUtil.intToBytes3(Integer.valueOf(logtime));
            int daysDiff = ArrayUtil.byte2int2(params);
            if (daysDiff == 0){
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(ecgHistroy, params), ArrayUtil.byteMerger(new byte[1], curT));
            } else {
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(ecgHistroy, params), new byte[]{0x00, 0x17});
            }
        } else if (id == FIT_GET_AUTO_ECG_DATA) {
            byte[] autoECGHistory = new byte[]{0x01,0x02,0x07,0x00};
            SimpleDateFormat format = new SimpleDateFormat("HH");
            Date curD = new Date(java.lang.System.currentTimeMillis());
            String logtime = format.format(curD);
            byte[] curT = ArrayUtil.intToBytes3(Integer.valueOf(logtime));
            Log.i(TAG, "fitnessData: " + ArrayUtil.toHex(params));
            int daysDiff = ArrayUtil.byte2int2(params);
            if (daysDiff == 0){
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(autoECGHistory, params), ArrayUtil.byteMerger(new byte[1], curT));
            } else {
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(autoECGHistory, params), new byte[]{0x00, 0x17});
            }
        } else if (id == FIT_GET_HISTROY_TEMP) {
            byte[] TempHistory = new byte[]{0x01,0x05,0x07,0x00};
            SimpleDateFormat format = new SimpleDateFormat("HH");
            Date curD = new Date(java.lang.System.currentTimeMillis());
            String logtime = format.format(curD);
            byte[] curT = ArrayUtil.intToBytes3(Integer.valueOf(logtime));
            int daysDiff = ArrayUtil.byte2int2(params);
            if (daysDiff == 0){
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(TempHistory, params), ArrayUtil.byteMerger(new byte[1], curT));
            } else {
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(TempHistory, params), new byte[]{0x00, 0x17});
            }
        } else if (id == FIT_GET_5_MINUTES_WALK) {
            byte[] FIT_GET_5_MINUTES_WALK = new byte[]{0x01,0x06,0x07,0x00};
            SimpleDateFormat format = new SimpleDateFormat("HH");
            Date curD = new Date(java.lang.System.currentTimeMillis());
            String logtime = format.format(curD);
            byte[] curT = ArrayUtil.intToBytes3(Integer.valueOf(logtime));
            int daysDiff = ArrayUtil.byte2int2(params);
            if (daysDiff == 0){
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_5_MINUTES_WALK, params), ArrayUtil.byteMerger(new byte[1], curT));
            } else {
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_5_MINUTES_WALK, params), new byte[]{0x00, 0x17});
            }
        } else if (id == FIT_GET_HOURLY_WALK_DATA) {
            byte[] FIT_GET_HOURLY_WALK_DATA = new byte[]{0x01,0x07,0x07,0x00};
            SimpleDateFormat format = new SimpleDateFormat("HH");
            Date curD = new Date(java.lang.System.currentTimeMillis());
            String logtime = format.format(curD);
            byte[] curT = ArrayUtil.intToBytes3(Integer.valueOf(logtime));
            int daysDiff = ArrayUtil.byte2int2(params);
            if (daysDiff == 0){
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_HOURLY_WALK_DATA, params), ArrayUtil.byteMerger(new byte[1], curT));
            } else {
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_HOURLY_WALK_DATA, params), new byte[]{0x00, 0x17});
            }
        } else if (id == FIT_GET_10_MINUTES_SLEEP) {
            byte[] FIT_GET_10_MINUTES_SLEEP = new byte[]{0x01,0x08,0x07,0x00};
            SimpleDateFormat format = new SimpleDateFormat("HH");
            Date curD = new Date(java.lang.System.currentTimeMillis());
            String logtime = format.format(curD);
            byte[] curT = ArrayUtil.intToBytes3(Integer.valueOf(logtime));
            int daysDiff = ArrayUtil.byte2int2(params);
            if (daysDiff == 0){
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_10_MINUTES_SLEEP, params), ArrayUtil.byteMerger(new byte[1], curT));
            } else {
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_10_MINUTES_SLEEP, params), new byte[]{0x00, 0x17});
            }
        } else if (id == FIT_GET_SPO2_RAW_125hz) {
            byte[] FIT_GET_SPO2_RAW_125hz = new byte[]{0x01,0x09,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_GET_SPO2_RAW_125hz, params);
        } else if (id == FIT_GET_LATEST_HEALTH_DATA) {
            byte[] FIT_GET_LATEST_HEALTH_DATA = new byte[]{0x01,0x0A,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_GET_LATEST_HEALTH_DATA, params);
        } else if (id == FIT_GET_1_MINUTES_SLEEP) {
            byte[] FIT_GET_1_MINUTES_SLEEP = new byte[]{0x01, 0x0c, 0x07, 0x00};
            byte[] ret = ArrayUtil.byteMerger(params, new byte[]{0x0c,0x0b});
            data = ArrayUtil.byteMerger(FIT_GET_1_MINUTES_SLEEP, ret);
        } else if (id == FIT_GET_5_MINUTES_RUNNING) {
            byte[] FIT_GET_5_MINUTES_RUNNING = new byte[]{0x01,0x0D,0x07,0x00};
            SimpleDateFormat format = new SimpleDateFormat("HH");
            Date curD = new Date(java.lang.System.currentTimeMillis());
            String logtime = format.format(curD);
            byte[] curT = ArrayUtil.intToBytes3(Integer.valueOf(logtime));
            int daysDiff = ArrayUtil.byte2int2(params);
            if (daysDiff == 0){
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_5_MINUTES_RUNNING, params), ArrayUtil.byteMerger(new byte[1], curT));
            } else {
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_5_MINUTES_RUNNING, params), new byte[]{0x00, 0x17});
            }
        } else if (id == FIT_GET_CLIMBING_HISTROY) {
            byte[] FIT_GET_CLIMBING_HISTROY = new byte[]{0x01,0x0E,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_GET_CLIMBING_HISTROY, params);
        } else if (id == FIT_GET_1_MINUTES_CYCLING) {
            byte[] FIT_GET_1_MINUTES_CYCLING = new byte[]{0x01,0x0F,0x07,0x00};
            SimpleDateFormat format = new SimpleDateFormat("HH");
            Date curD = new Date(java.lang.System.currentTimeMillis());
            String logtime = format.format(curD);
            byte[] curT = ArrayUtil.intToBytes3(Integer.valueOf(logtime));
            int daysDiff = ArrayUtil.byte2int2(params);
            if (daysDiff == 0){
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_1_MINUTES_CYCLING, params), ArrayUtil.byteMerger(new byte[1], curT));
            } else {
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_1_MINUTES_CYCLING, params), new byte[]{0x00, 0x17});
            }
        } else if (id == FIT_GET_ACTIVITE_HISTROY) {
            byte[] FIT_GET_ACTIVITE_HISTROY = new byte[]{0x01,0x10,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_GET_ACTIVITE_HISTROY, params);
        } else if (id == FIT_GET_HISTROY_RR_INTERVAL) {
            byte[] FIT_GET_HISTROY_RR_INTERVAL = new byte[]{0x01,0x14,0x07,0x00};
            SimpleDateFormat format = new SimpleDateFormat("HH");
            Date curD = new Date(java.lang.System.currentTimeMillis());
            String logtime = format.format(curD);
            byte[] curT = ArrayUtil.intToBytes3(Integer.valueOf(logtime));
            int daysDiff = ArrayUtil.byte2int2(params);
            if (daysDiff == 0){
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_HISTROY_RR_INTERVAL, params), ArrayUtil.byteMerger(new byte[1], curT));
            } else {
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_HISTROY_RR_INTERVAL, params), new byte[]{0x00, 0x17});
            }
        } else if (id == FIT_GET_GPS_DATA) {
            byte[] FIT_GET_GPS_DATA = new byte[]{0x01,0x15,0x07,0x00};
            SimpleDateFormat format = new SimpleDateFormat("HH");
            Date curD = new Date(java.lang.System.currentTimeMillis());
            String logtime = format.format(curD);
            byte[] curT = ArrayUtil.intToBytes3(Integer.valueOf(logtime));
            int daysDiff = ArrayUtil.byte2int2(params);
            if (daysDiff == 0){
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_GPS_DATA, params), ArrayUtil.byteMerger(new byte[1], curT));
            } else {
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_GPS_DATA, params), new byte[]{0x00, 0x17});
            }
        } else if (id == FIT_OBTAIN_HR_BP_VALUE) {
            byte[] FIT_OBTAIN_HR_BP_VALUE = new byte[]{0x01,0x19,0x04,0x00};
            data = FIT_OBTAIN_HR_BP_VALUE;
        } else if (id == FIT_GET_PROXIMLY_ALART) {
            byte[] FIT_GET_PROXIMLY_ALART = new byte[]{0x01,0x1A,0x04,0x00};
            data = FIT_GET_PROXIMLY_ALART;
        } else if (id == FIT_GET_LIVE_TEMP_DATA) {
            byte[] FIT_GET_LIVE_TEMP_DATA = new byte[]{0x01,0x1B,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_GET_LIVE_TEMP_DATA, params);
        } else if (id == FIT_GET_CONTACT_TRACING_SUMMARY) {
            byte[] FIT_GET_CONTACT_TRACING_SUMMARY = new byte[]{0x01,0x1c,0x04,0x00};
            data = FIT_GET_CONTACT_TRACING_SUMMARY;
        } else if (id == FIT_GET_CONTACT_TRACING_SPECIFIED) {
            byte[] FIT_GET_CONTACT_TRACING_SPECIFIED = new byte[]{0x01,0x0d,0x0c,0x00};
        } else if (id == FIT_GET_HISTROY_PPG_RAW) {
            byte[] FIT_GET_HISTROY_PPG_RAW = new byte[]{0x01,0x0e,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_GET_HISTROY_PPG_RAW, params);
        } else if (id == FIT_GET_HISTROY_ACC_RAW) {
            byte[] FIT_GET_HISTROY_ACC_RAW = new byte[]{0x01,0x0f,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_GET_HISTROY_ACC_RAW, params);
        } else if (id == FIT_GET_SEDENTARY_ALART) {
            byte[] FIT_GET_SEDENTARY_ALART = new byte[]{0x01,0x20,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_GET_SEDENTARY_ALART, params);
        } else if (id == FIT_GET_ACTIVITY_CONFIG) {
            byte[] FIT_GET_ACTIVITY_CONFIG = new byte[]{0x01,0x21,0x04,0x00};
            data = FIT_GET_ACTIVITY_CONFIG;
        } else if (id == FIT_GET_ACTIVITY_CONFIG_NEW) {
            byte[] FIT_GET_ACTIVITY_CONFIG_NEW = new byte[]{0x01,0x22,0x04,0x00};
            data = FIT_GET_ACTIVITY_CONFIG_NEW;
        } else if (id == FIT_GET_ACTIVITY_CONFIG_SUMMARY) {
            byte[] FIT_GET_ACTIVITY_CONFIG_SUMMARY = new byte[]{0x01,0x23,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_GET_ACTIVITY_CONFIG_SUMMARY, params);
        } else if (id == FIT_GET_ACTIVITY_CONFIG_DETAIL) {
            byte[] FIT_GET_ACTIVITY_CONFIG_DETAIL = new byte[]{0x01,0x24,0x0a,0x00};
        } else if (id == FIT_GET_SP02_PARA) {
            byte[] FIT_GET_SP02_PARA = new byte[]{0x01,0x25,0x04,0x00};
            data = FIT_GET_SP02_PARA;
        } else if (id == FIT_GET_SP02_DATA) {
            byte[] FIT_GET_SP02_DATA = new byte[]{0x01,0x26,0x07,0x00};
            SimpleDateFormat format = new SimpleDateFormat("HH");
            Date curD = new Date(java.lang.System.currentTimeMillis());
            String logtime = format.format(curD);
            byte[] curT = ArrayUtil.intToBytes3(Integer.valueOf(logtime));
            int daysDiff = ArrayUtil.byte2int2(params);
            if (daysDiff == 0){
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_SP02_DATA, params), ArrayUtil.byteMerger(new byte[1], curT));
            } else {
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_SP02_DATA, params), new byte[]{0x00, 0x17});
            }
        } else if (id == FIT_GET_SLEEP_TARGET_VALUE) {
            byte[] FIT_GET_SLEEP_TARGET_VALUE = new byte[]{0x01,0x28,0x04,0x00};
            data = FIT_GET_SLEEP_TARGET_VALUE;
        } else if (id == FIT_GET_SLEEP_SUMMARY_DATA) {
            byte[] FIT_GET_SLEEP_SUMMARY_DATA = new byte[]{0x01,0x29,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_GET_SLEEP_SUMMARY_DATA, params);
        } else if (id == FIT_GET_SENSAI_CONFIG) {
            byte[] FIT_GET_SENSAI_CONFIG = new byte[]{0x01,0x2A,0x04,0x00};
            data = FIT_GET_SENSAI_CONFIG;
        } else if (id == FIT_GET_SENSAI_SUMMARY) {
            byte[] FIT_GET_SENSAI_SUMMARY = new byte[]{0x01,0x2b,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_GET_SENSAI_SUMMARY, params);
        } else if (id == FIT_GET_SENSAI_DETAIL) {
            byte[] FIT_GET_SENSAI_DETAIL = new byte[]{0x01,0x2c,0x09,0x00};
        } else if (id == FIT_GET_HISTROY_DISTANCE) {
            byte[] FIT_GET_HISTROY_DISTANCE = new byte[]{0x01,0x2d,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_GET_HISTROY_DISTANCE, params);
        } else if (id == FIT_GET_HISTROY_CALORIE) {
            byte[] FIT_GET_HISTROY_CALORIE = new byte[]{0x01,0x2e,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_GET_HISTROY_CALORIE, params);
        } else if (id == FIT_GET_TODAY_FITNESS) {
            byte[] FIT_GET_TODAY_FITNESS = new byte[]{0x01,0x2f,0x04,0x00};
            data = FIT_GET_TODAY_FITNESS;
        } else if (id == FIT_GET_HISTROY_STRESS) {
            byte[] FIT_GET_HISTROY_STRESS = new byte[]{0x01, (byte) 0xaa,0x08,0x00,0x40};
            SimpleDateFormat format = new SimpleDateFormat("HH");
            Date curD = new Date(java.lang.System.currentTimeMillis());
            String logtime = format.format(curD);
            byte[] curT = ArrayUtil.intToBytes3(Integer.valueOf(logtime));
            int daysDiff = ArrayUtil.byte2int2(params);
            if (daysDiff == 0){
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_HISTROY_STRESS, params), ArrayUtil.byteMerger(new byte[1], curT));
            } else {
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(FIT_GET_HISTROY_STRESS, params), new byte[]{0x00, 0x17});
            }
        } else if (id == FIT_GET_FIRMWARE_CAPABILITY) {
            byte[] FIT_GET_FIRMWARE_CAPABILITY = new byte[]{0x01, (byte) 0xac,0x05,0x00,0x40};
            data = FIT_GET_FIRMWARE_CAPABILITY;
        } else if (id == FIT_GET_4H_FUNCTION) {
            byte[] FIT_GET_4H_FUNCTION = new byte[]{0x01, (byte) 0xAF,0x05,0x00,0x40};
            data = FIT_GET_4H_FUNCTION;
        } else if (id == FIT_GET_ACTIVITY_GUIDE) {
            byte[] FIT_GET_ACTIVITY_GUIDE = new byte[]{0x01, (byte) 0xb0,0x05,0x00,0x40};
            data = FIT_GET_ACTIVITY_GUIDE;
        } else if (id == FIT_SET_DAILY_WALKING) {
            byte[] FIT_SET_DAILY_WALKING = new byte[]{0x01, (byte) 0x80,0x08,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_DAILY_WALKING, params);
        } else if (id == FIT_SET_AUTO_HR_INTERVAL) {
            byte[] FIT_SET_AUTO_HR_INTERVAL = new byte[]{0x01, (byte) 0x83,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_AUTO_HR_INTERVAL, params);
        } else if (id == FIT_SET_ECG_RAW_DATA) {
            byte[] FIT_SET_ECG_RAW_DATA = new byte[]{0x01, (byte) 0x84,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_ECG_RAW_DATA, params);
        } else if (id == FIT_SET_HR_LIVE_CONTROL) {
            byte[] FIT_SET_HR_LIVE_CONTROL = new byte[]{0x01, (byte) 0x85,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_HR_LIVE_CONTROL, params);
        } else if (id == FIT_SET_SPO2_LIVE_CONTROL) {
            byte[] FIT_SET_SPO2_LIVE_CONTROL = new byte[]{0x01, (byte) 0x86,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_SPO2_LIVE_CONTROL, params);
        } else if (id == FIT_SET_ERASE_FITNESS_DATA) {
            byte[] FIT_SET_ERASE_FITNESS_DATA = new byte[]{0x01, (byte) 0x89,0x06,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_ERASE_FITNESS_DATA, params);
        } else if (id == FIT_SET_BP_LIVE_CONTROL) {
            byte[] FIT_SET_BP_LIVE_CONTROL = new byte[]{0x01, (byte) 0x8A,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_BP_LIVE_CONTROL, params);
        } else if (id == FIT_SET_SPORT_MODE) {
            byte[] FIT_SET_SPORT_MODE = new byte[]{0x01, (byte) 0x8B,0x06,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_SPORT_MODE, params);
        } else if (id == FIT_SET_UPDATA_HR_ZONE_VALUE) {
            byte[] FIT_SET_UPDATA_HR_ZONE_VALUE = new byte[]{0x01, (byte) 0x92,0x09,0x00};
            byte[] ret = ArrayUtil.byteMerger(params,new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF});
            data = ArrayUtil.byteMerger(FIT_SET_UPDATA_HR_ZONE_VALUE, ret);
        } else if (id == FIT_SET_UPDATA_VO2_MAX_VALUE) {
            byte[] FIT_SET_UPDATA_VO2_MAX_VALUE = new byte[]{0x01, (byte) 0x91,0x08,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_UPDATA_VO2_MAX_VALUE, params);
        } else if (id == FIT_SET_LIVE_STEPS_CONTROL) {
            byte[] FIT_SET_LIVE_STEPS_CONTROL = new byte[]{0x01, (byte) 0x93,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_LIVE_STEPS_CONTROL, params);
        } else if (id == FIT_SET_GPS_CONTROL) {
            byte[] FIT_SET_GPS_CONTROL = new byte[]{0x01, (byte) 0x96,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_GPS_CONTROL, params);
        } else if (id == FIT_SET_SPORT_MODE_PAUSE) {
            byte[] FIT_SET_SPORT_MODE_PAUSE = new byte[]{0x01, (byte) 0x97,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_SPORT_MODE_PAUSE, params);
        } else if (id == FIT_SET_SYNC_BP_PARAMS) {
            byte[] FIT_SET_SYNC_BP_PARAMS = new byte[]{0x01, (byte) 0x98,0x08,0x00};
        } else if (id == FIT_SET_CLEAR_USER_BP_DATA) {
            byte[] FIT_SET_CLEAR_USER_BP_DATA = new byte[]{0x01, (byte) 0x99,0x04,0x00};
            data = FIT_SET_CLEAR_USER_BP_DATA;
        } else if (id == FIT_SET_CLEAR_CONTACT_TRACING_DATA) {
            byte[] FIT_SET_CLEAR_CONTACT_TRACING_DATA = new byte[]{0x01, (byte) 0x9a,0x04,0x00};
            data = FIT_SET_CLEAR_CONTACT_TRACING_DATA;
        } else if (id == FIT_SET_AUTO_PPG_INTERVAL) {
            byte[] FIT_SET_AUTO_PPG_INTERVAL = new byte[]{0x01, (byte) 0x9E,0x0C,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_AUTO_PPG_INTERVAL,params);
        } else if (id == FIT_SET_AUTO_ACC_INTERVAL) {
            byte[] FIT_SET_AUTO_ACC_INTERVAL = new byte[]{0x01, (byte) 0x9E,0x07,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_AUTO_ACC_INTERVAL,params);
        } else if (id == FIT_SET_SPO2_PERIODIC) {
            byte[] FIT_SET_SPO2_PERIODIC = new byte[]{0x01, (byte) 0xA5,0x0A,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_SPO2_PERIODIC,params);
        } else if (id == FIT_SET_SLEEP_TARGET_VALUE) {
            byte[] FIT_SET_SLEEP_TARGET_VALUE = new byte[]{0x01, (byte) 0xA8,0x06,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_SLEEP_TARGET_VALUE,params);
        } else if (id == FIT_SET_STRESS_CONFIG) {
            byte[] FIT_SET_STRESS_CONFIG = new byte[]{0x01, (byte) 0xA9,0x14,0x00,0x41};
            byte[] reserved = new byte[6];
            data = ArrayUtil.byteMerger(FIT_SET_STRESS_CONFIG,ArrayUtil.byteMerger(params, reserved));
        } else if (id == FIT_SET_HAR_CONFIG) {
            byte[] FIT_SET_HAR_CONFIG = new byte[]{0x01, (byte) 0xAB,0x15,0x00,0x41};
            data = ArrayUtil.byteMerger(FIT_SET_HAR_CONFIG,params);
        } else if (id == FIT_GET_HAR_CONFIG) {
            byte[] FIT_GET_HAR_CONFIG = new byte[]{0x01, (byte) 0xAB,0x05,0x00,0x40};
            data = FIT_GET_HAR_CONFIG;
        } else if (id == FIT_SET_SENSAI_CONFIG) {
            byte[] FIT_SET_SENSAI_CONFIG = new byte[]{0x01, (byte) 0xAD,0x06,0x00,0x41};
            data = ArrayUtil.byteMerger(FIT_SET_SENSAI_CONFIG, params);
        } else if (id == FIT_SET_START_DESIGNATED_ACT) {
            byte[] FIT_SET_START_DESIGNATED_ACT = new byte[]{0x01, (byte) 0xAE,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_START_DESIGNATED_ACT, params);
        } else if (id == FIT_SET_4H_BUTTON_FUNCTION) {
            byte[] FIT_SET_START_DESIGNATED_ACT = new byte[]{0x01, (byte) 0xAE,0x05,0x00};
            data = ArrayUtil.byteMerger(FIT_SET_START_DESIGNATED_ACT, params);
        }
        Log.i(TAG, "fitnessData: " + ArrayUtil.toHex(data));
        return data;
    }
    public static byte[] AlarmNotifyData(int id, byte[] params){
        byte[] data = new byte[100];
        switch (id){
            case ALARM_GET_ALARM_INFO:
                byte[] ALARM_GET_ALARM_INFO = new byte[]{0x02,0x05,0x04,0x00};
                data = ALARM_GET_ALARM_INFO;
                break;
            case ALARM_GET_DND_setting:
                byte[] ALARM_GET_DND_setting = new byte[]{0x02,0x09,0x04,0x00};
                data = ALARM_GET_DND_setting;
                break;
            case ALARM_GET_WATCH_FACE_LIST:
                byte[] ALARM_GET_WATCH_FACE_LIST = new byte[]{0x02,0x0D,0x04,0x00};
                data = ALARM_GET_WATCH_FACE_LIST;
                break;
            case ALARM_GET_CUR_WATCH_FACE_ID:
                byte[] ALARM_GET_CUR_WATCH_FACE_ID = new byte[]{0x02,0x0F,0x04,0x00};
                data = ALARM_GET_CUR_WATCH_FACE_ID;
                break;
            case ALARM_GET_SPORTS_NOTIFI_STATUS:
                byte[] ALARM_GET_SPORTS_NOTIFI_STATUS = new byte[]{0x02,0x10,0x04,0x00};
                data = ALARM_GET_SPORTS_NOTIFI_STATUS;
                break;
            case ALARM_GET_IMAGE_LIST:
                byte[] ALARM_GET_IMAGE_LIST = new byte[]{0x02,0x13,0x04,0x00};
                data = ALARM_GET_IMAGE_LIST;
                break;
            case ALARM_GET_WATCH_BK_IMGID:
                byte[] ALARM_GET_WATCH_BK_IMGID = new byte[]{0x02,0x16,0x04,0x00};
                data = ALARM_GET_WATCH_BK_IMGID;
                break;
            case ALARM_GET_QUICK_REPLY_LIST:
                byte[] ALARM_GET_QUICK_REPLY_LIST = new byte[]{0x02,0x17,0x04,0x00};
                data = ALARM_GET_QUICK_REPLY_LIST;
                break;
            case ALARM_GET_WOMEN_HEALTH_DATA:
                byte[] ALARM_GET_WOMEN_HEALTH_DATA = new byte[]{0x02,0x18,0x04,0x00};
                data = ALARM_GET_WOMEN_HEALTH_DATA;
                break;
            case ALARM_GET_FIND_WATCH:
                byte[] ALARM_GET_FIND_WATCH = new byte[]{0x01, (byte) 0xAC,0x05,0x00,0x40};
                data = ALARM_GET_FIND_WATCH;
                break;
            case ALARM_GET_FIND_WATCH_START:
                byte[] ALARM_GET_FIND_WATCH_START = new byte[]{0x02, (byte) 0xA5,0x06,0x00};
                data = ArrayUtil.byteMerger(ALARM_GET_FIND_WATCH_START, params);
                break;
            case ALARM_SET_DEVICE_EVENT:
                byte[] ALARM_SET_DEVICE_EVENT = new byte[]{0x02, (byte) 0x12,0x06,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_DEVICE_EVENT, params);
                break;
            case ALARM_SET_SEDENTARY_ALART:
                byte[] ALARM_SET_SEDENTARY_ALART = new byte[]{0x02, (byte) 0x80,0x0e,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_SEDENTARY_ALART, params);
                break;
            case ALARM_SET_MUSIC_STATUS:
                byte[] ALARM_SET_MUSIC_STATUS = new byte[]{0x02, (byte) 0x81,0x05,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_MUSIC_STATUS, params);
                break;
            case ALARM_SET_MESSAGE_ALART:
                byte[] ALARM_SET_MESSAGE_ALART = new byte[]{0x02, (byte) 0x82,0x06,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_MESSAGE_ALART, params);
                break;
            case ALARM_SET_MESSAGE_CONTENT:
                byte[] ALARM_SET_MESSAGE_CONTENT = new byte[]{0x02, (byte) 0x83,0x0a,0x00};
                byte[] fullData = ArrayUtil.byteMerger(ALARM_SET_MESSAGE_CONTENT, params);
                data = fullData;
                break;
            case ALARM_SET_ALARM_INFO:
                byte[] ALARM_SET_ALARM_INFO = new byte[]{0x02, (byte) 0x85,0x0f,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_ALARM_INFO, params);
                break;
            case ALARM_SET_MEETING_SYNC:
                byte[] ALARM_SET_MEETING_SYNC = new byte[]{0x02, (byte) 0x87,0x0e,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_MEETING_SYNC, params);
                break;
            case ALARM_SET_MEETING_DELETE:
                byte[] ALARM_SET_MEETING_DELETE = new byte[]{0x02, (byte) 0x88,0x0a,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_MEETING_DELETE, params);
                break;
            case ALARM_SET_DND_MODE:
                byte[] ALARM_SET_DND_MODE = new byte[]{0x02, (byte) 0x89,0x0b,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_DND_MODE, params);
                break;
            case ALARM_SET_MUSIC_ARTIST:
                byte[] ALARM_SET_MUSIC_ARTIST = new byte[]{0x02, (byte) 0x8a,0x0c,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_MUSIC_ARTIST, params);
                break;
            case ALARM_SET_MUSIC_NAME:
                byte[] ALARM_SET_MUSIC_NAME = new byte[]{0x02, (byte) 0x8b,0x0e,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_MUSIC_NAME, params);
                break;
            case ALARM_SET_STOP_CUR_MESSAGE:
                byte[] ALARM_SET_STOP_CUR_MESSAGE = new byte[]{0x02, (byte) 0x8c,0x05,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_STOP_CUR_MESSAGE, params);
                break;
            case ALARM_SET_CUR_WATCH_FACE_ID:
                byte[] ALARM_SET_CUR_WATCH_FACE_ID = new byte[]{0x02, (byte) 0x8F,0x06,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_CUR_WATCH_FACE_ID, params);
                break;
            case ALARM_SET_DELETE_WATCH_FACE_ID:
                byte[] ALARM_SET_DELETE_WATCH_FACE_ID = new byte[]{0x02, (byte) 0x90,0x06,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_DELETE_WATCH_FACE_ID, params);
                break;
            case ALARM_SET_SPORTS_NOTIFY_SWITCH:
                byte[] ALARM_SET_SPORTS_NOTIFY_SWITCH = new byte[]{0x02, (byte) 0x91,0x05,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_SPORTS_NOTIFY_SWITCH, params);
                break;
            case ALARM_SET_DELETE_IMAGE:
                byte[] ALARM_SET_DELETE_IMAGE = new byte[]{0x02, (byte) 0x95,0x06,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_DELETE_IMAGE, params);
                break;
            case ALARM_SET_WATCH_FACE_BK_IMG:
                byte[] ALARM_SET_WATCH_FACE_BK_IMG = new byte[]{0x02, (byte) 0x96,0x08,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_WATCH_FACE_BK_IMG, params);
                break;
            case ALARM_SET_UP_QUICK_REPLY_LIST:
                byte[] ALARM_SET_UP_QUICK_REPLY_LIST = new byte[]{0x02, (byte) 0x97};
                data = ArrayUtil.byteMerger(ArrayUtil.byteMerger(ALARM_SET_UP_QUICK_REPLY_LIST, ArrayUtil.intToBytes2(4 + params.length)), params);
                break;
            case ALARM_SET_WOMEN_HEALTH_DATA:
                byte[] ALARM_SET_WOMEN_HEALTH_DATA = new byte[]{0x02, (byte) 0x98,0x13,0x00};
                data = ArrayUtil.byteMerger(ALARM_SET_WOMEN_HEALTH_DATA, params);
                break;
            default:
                break;
        }
        Log.i(TAG, "AlarmNotifyData: " + ArrayUtil.toHex(data));
        return data;
    }
    public static byte[] VibratorData(int id, byte[] params){
        byte[] data = new byte[100];
        switch (id){
            case VIBRATOR_GET_CONFIG:
                byte[] VIBRATOR_GET_CONFIG = new byte[]{0x04,0x00,0x04,0x00};
                data = VIBRATOR_GET_CONFIG;
                break;
            case VIBRATOR_SET_CONFIG:
                byte[] VIBRATOR_SET_CONFIG = new byte[]{0x04,0x00,0x04,0x00};
                data = ArrayUtil.byteMerger(VIBRATOR_SET_CONFIG, params);
                break;
            default:
                break;
        }
        return data;
    }
    public static byte[] SystemData(int id, byte[] params){
        byte[] data = new byte[100];
        switch (id){
            case SYSTEM_GET_BRIGHT_SCREEN_TIME:
                byte[] SYSTEM_GET_BRIGHT_SCREEN_TIME = new byte[]{0x06,0x06,0x04,0x00};
                data = SYSTEM_GET_BRIGHT_SCREEN_TIME;
                break;
            case SYSTEM_DIAGNOSTICS_MODE:
                byte[] SYSTEM_DIAGNOSTICS_MODE = new byte[]{0x06,0x07,0x06,0x00,0x41};
                data = ArrayUtil.byteMerger(SYSTEM_DIAGNOSTICS_MODE, params);
                break;
            case SYSTEM_DIAGNOSTICS_MODE_CONFIG:
                byte[] SYSTEM_DIAGNOSTICS_MODE_CONFIG = new byte[]{0x06,0x08};
                data = ArrayUtil.byteMerger(SYSTEM_DIAGNOSTICS_MODE_CONFIG, params);
                break;
            case SYSTEM_RESET_SYSTEM:
                byte[] SYSTEM_RESET_SYSTEM = new byte[]{0x06, (byte) 0x81,0x04,0x00};
                data = SYSTEM_RESET_SYSTEM;
                break;
            case SYSTEM_POWER_OFF:
                byte[] SYSTEM_POWER_OFF = new byte[]{0x06, (byte) 0x82,0x04,0x00};
                data = SYSTEM_POWER_OFF;
                break;
            case SYSTEM_POWER_SAVING_CONFIG:
                byte[] SYSTEM_POWER_SAVING_CONFIG = new byte[]{0x06, (byte) 0x88,0x08,0x00,0x41};
                data = ArrayUtil.byteMerger(SYSTEM_POWER_SAVING_CONFIG, params);
                break;
            case SYSTEM_GET_POWER_STATUS:
                byte[] SYSTEM_GET_POWER_STATUS = new byte[]{0x06, (byte) 0x88,0x05,0x00,0x40};
                data = SYSTEM_GET_POWER_STATUS;
                break;
            case SYSTEM_GET_SILENCE_MODE:
                byte[] SYSTEM_GET_SILENCE_MODE = new byte[]{0x06, (byte) 0x89,0x05,0x00,0x40};
                data = SYSTEM_GET_SILENCE_MODE;
                break;
            case SYSTEM_SET_SILENCE_MODE_CONFIG:
                byte[] SYSTEM_GET_SILENCE_MODE_CONFIG = new byte[]{0x06, (byte) 0x89,0x07,0x00,0x41};
                data = ArrayUtil.byteMerger(SYSTEM_GET_SILENCE_MODE_CONFIG, params);
                break;
            default:
                break;
        }
        return data;
    }

    public static byte[] developTest(int id, byte[] params){
        byte[] data = new byte[100];
        if (id == TEST_GET_LOG_FILE_NAME) {
            byte[] getFileName = new byte[]{0x08, 0x0E, 0x04, 0x00};
            data = getFileName;
        } else if (id == TEST_REQUEST_LOG_BY_FILE_NAME) {
            int codeLen = 5 + params.length;
            byte[] File = new byte[params.length - 1];
            System.arraycopy(params, 0, File, 0 , File.length);
            mFileName = ArrayUtil.toASCII(File);
            Log.i(TAG, "developTest: -----" + mFileName);
            byte[] codeLenth = ArrayUtil.intToBytes2(codeLen);
            byte[] request = new byte[]{0x08,0x0F, codeLenth[0],codeLenth[1]};
            byte[] paramsLen = ArrayUtil.intToBytes2(params.length);
            byte[] ret = new byte[5 + params.length];
            System.arraycopy(request,0,ret, 0, 4);
            System.arraycopy(paramsLen, 0, ret, 4,1);
            System.arraycopy(params,0,ret,5,params.length);
            data = ret;
        } else if (id == TEST_START_LOG_OUTPUT) {
            byte[] TEST_START_LOG_OUTPUT = new byte[]{0x08, (byte) 0x8b,0x07,0x00};
            data = ArrayUtil.byteMerger(TEST_START_LOG_OUTPUT, params);
            Log.i(TAG, "developTest: " + params[0]);
            byte[] tag = new byte[1];
            tag[0] = params[0];
            if (ArrayUtil.byte2int2(tag) != 1){
                Log.i(TAG, "setAlgoFileName: ");
                sleepLogDump = 1;
                setAlgoFileName();
            }
        }
        Log.i(TAG, "developTest: " + ArrayUtil.toHex(data));
        return data;
    }

    public static void setAlgoFileName(){
        SimpleDateFormat format = new SimpleDateFormat("yyyy:MM:dd:HH:mm:ss");
        Date curD = new Date(java.lang.System.currentTimeMillis());
        logName = format.format(curD) + "_ALGO_LOG";
        Log.i(TAG, "developTest: " + logName);
    }

    public static void dataSplit(byte[] bytes){
        try {
            Log.i(TAG, "bytes: " + bytes.length);
            int len = bytes.length + 4;
            int remainder = len % Constants.GENERAL_PROTOCOL_PKG_MAX_LEN;
            boolean isLastData = (remainder != 0);
            int count = len / Constants.GENERAL_PROTOCOL_PKG_MAX_LEN + (isLastData ? 1 : 0);
            if (count > 65530){
                Log.i(TAG, "totalCount: " + count + ", > 65535 protocol not support");
                return ;
            }
            Log.i(TAG, "totalCount: " + count);
            byte[] totalCount = ArrayUtil.intToBytes2(count);
            byte[] multiHead = new byte[8];
            long cRC32Len = ArrayUtil.crc32(bytes,0, bytes.length);
            byte[] crc_offset_byte = new byte[4];
            crc_offset_byte[0] =(byte) cRC32Len;
            crc_offset_byte[1] = (byte) (cRC32Len >> 8);
            crc_offset_byte[2] = (byte) (cRC32Len >> 16);
            crc_offset_byte[3] = (byte) (cRC32Len >> 24);
            Log.i(TAG, "dataSplit: -------cRC32 Len==="+cRC32Len + ",crc_offset_byte: " + ArrayUtil.toHex(crc_offset_byte));
            multiHead[0] = totalCount[0];
            multiHead[1] = totalCount[1];
            multiHead[2] = crc_offset_byte[0]; //crc_l
            multiHead[3] = crc_offset_byte[1]; //crc_H
            Log.i(TAG, "multiHead: " + ArrayUtil.toHex(multiHead));

            byte[] multiData = new byte[len];
            System.arraycopy(multiHead, 0, multiData, 0, 4);
            System.arraycopy(bytes, 0 ,multiData, 4, bytes.length);

            if (count >= 1) {
                int curL = 0;
                for (int i = 0; i < count; i++) {
                    byte[] pkgData = new byte[Constants.GENERAL_PROTOCOL_PKG_MAX_LEN+4];
                    pkgData[0] = (byte) 0x7f;
                    byte[] countNum = ArrayUtil.intToBytes2(i);
                    pkgData[1] = crc_offset_byte[0];
                    pkgData[2] = countNum[0];
                    pkgData[3] = countNum[1];
                    Log.i(TAG, "initView: ====" + i);
                    Log.i(TAG, "initView: ----" + len+ "----------"+curL);
                    if (curL < Constants.GENERAL_PROTOCOL_PKG_MAX_LEN && i > 0){
                        pkgData = new byte[curL + 4];
                        pkgData[0] = (byte) 0x7f;
                        pkgData[1] = crc_offset_byte[0]; //crc_L
                        pkgData[2] = countNum[0];
                        pkgData[3] = countNum[1];
                        System.arraycopy(multiData, len - curL, pkgData, 4, curL);
                        singlePacket.add(i, pkgData);
                        Log.i(TAG, "dataSplit<" + Constants.GENERAL_PROTOCOL_PKG_MAX_LEN + ": -----"+ ArrayUtil.toHex(singlePacket.get(i)));
                        return ;
                    }
                    if (len < Constants.GENERAL_PROTOCOL_PKG_MAX_LEN){
                        System.arraycopy(multiData, i * len, pkgData, 4, len);
                    }else{
                        System.arraycopy(multiData, i * Constants.GENERAL_PROTOCOL_PKG_MAX_LEN, pkgData, 4, Constants.GENERAL_PROTOCOL_PKG_MAX_LEN);
                    }
                    singlePacket.add(pkgData);
                    curL = len - Constants.GENERAL_PROTOCOL_PKG_MAX_LEN * (i + 1);
                    //Log.i(TAG, "dataSplit: -----" + ArrayUtil.toHex(singlePacket.get(i)));
                }
                Log.i(TAG, "totalNum===: -----" + singlePacket.size());
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static boolean getPhoneBookDataPacket(byte[] params){
        byte[] setBook = new byte[]{0x00, (byte) 0xA8};
        int len = setBook.length + params.length + 2;
        byte[] l = ArrayUtil.intToBytes2(len);
        byte[] ret = ArrayUtil.byteMerger(setBook, l);
        dataSplit(ArrayUtil.byteMerger(ret,params));
        return true;
    }

    public static boolean getDialOTAPacket(String path,String id) {
        singlePacket.clear();
        FileInputStream inputStream = null;
        byte[] iamgeBytes;
        try {
            inputStream = new FileInputStream(path);
            int totalSize = inputStream.available();
            Log.i("TAG", " totalSize: --------" + totalSize);
            int dataSize = totalSize;
            iamgeBytes = new byte[dataSize];
            inputStream.read(iamgeBytes, 0, dataSize);
            inputStream.close();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        Log.i(TAG, "getDialOTAPacket: " + iamgeBytes.length);
        byte[] watchDialOTA = new byte[]{0x02, (byte) 0x8e};
        int binLen = iamgeBytes.length;
        int CMDLen = 2 + binLen;
        byte[] CmdLen = ArrayUtil.intToBytes2(CMDLen);
        byte[] head = new byte[6];
        head = ArrayUtil.byteMerger(watchDialOTA, CmdLen);
        byte[] dial_id = ArrayUtil.toBytes(id);
        byte[] final_head = ArrayUtil.byteMerger(head, dial_id);
        byte[] body = ArrayUtil.byteMerger(ArrayUtil.intToBytesLittle(binLen), iamgeBytes);
        finalData = ArrayUtil.byteMerger(final_head, body);
        Log.i(TAG, "getDialOTAPacket: finalData" + ArrayUtil.toHex(finalData));
        dataSplit(finalData);

        return true;
    }

    public static void successSend(){
        PKGS++;
    }

    public static byte[] sendWatchDialPacket(){
        CommonUtil.saveCurrentPackageTotalNum(mContext,singlePacket.size());
        Log.i(TAG, "sendWatchDialPacket: " + PKGS);
        if (PKGS == (singlePacket.size())){
            Log.i(TAG, "sendWatchDialPacket: null");
            return new byte[]{0x00};
        }
        data = singlePacket.get(PKGS);
        return data;
    }

    public static void messageContent(byte[] params){
        byte[] ALARM_SET_MESSAGE_CONTENT = new byte[]{0x02, (byte) 0x83,0x0a,0x00};
        byte[] fullData = ArrayUtil.byteMerger(ALARM_SET_MESSAGE_CONTENT, params);
        dataSplit(fullData);
    }

    public static void quickRPList(byte[] params){
        byte[] ALARM_SET_UP_QUICK_REPLY_LIST = new byte[]{0x02, (byte) 0x97};
        byte[] fullData = ArrayUtil.byteMerger(ArrayUtil.byteMerger(ALARM_SET_UP_QUICK_REPLY_LIST, ArrayUtil.intToBytes2(4 + params.length)), params);
        dataSplit(fullData);
    }

    public static List<byte[]> getAllCmdPacket(){
        return singlePacket;
    }

    public static void otaSuccess(){
        PKGS = 0;
        singlePacket.clear();
        Log.i(TAG, "otaSuccess: " + singlePacket.size());
    }

    public static byte[] sendWatchDialPacket(Context context,int currentIndex){
        mContext = context;
        CommonUtil.saveCurrentPackageTotalNum(mContext,singlePacket.size());
        if (currentIndex == singlePacket.size()){
            Log.i(TAG, "sendWatchDialPacket: send total packet success pkg_currentPackageTotalNum====" + singlePacket.size());
            singlePacket.clear();
            return new byte[]{0x00};
        }
        data = singlePacket.get(currentIndex);
        return data;
    }

    public static byte[] getBytes(String str, int length) {
        int fixLength = length - str.getBytes().length;
        if (str.getBytes().length < length) {
            byte[] S_bytes = new byte[length];
            System.arraycopy(str.getBytes(), 0, S_bytes, 0, str.getBytes().length);
            for (int x = length-fixLength; x < length; x++) {
                S_bytes[x] = 0x00;
            }
            return S_bytes;
        }
        return str.getBytes();
    }

    public static boolean convertTransPacket(Context context,String path,String fileName) {
        mContext = context;
        mFileName = fileName;
        mReadType = BB_READ_CONFIG_INFO_TYPE;
        new readRouteBooksFilesTask().executeTask(path);
        /**
        singlePacket.clear();
        FileInputStream inputStream = null;
        byte[] inputBytes;
        try {
            inputStream = new FileInputStream(path);
            int totalSize = inputStream.available();
            Log.i("TAG", " totalSize: --------" + totalSize);
            int dataSize = totalSize;
            inputBytes = new byte[dataSize];
            inputStream.read(inputBytes, 0, dataSize);
            inputStream.close();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        Log.i(TAG, "convertTransPacket: " + inputBytes.length);
        byte[] commonCMD = new byte[]{(byte)0x00, (byte) 0x00};
        if (mFileName.contains(SettingsJsonUtils.ROUTE_BOOKS_JSON)){
            commonCMD = new byte[]{(byte)0x0d, (byte) 0xc5};
        } else if(mFileName.contains(SettingsJsonUtils.PANEL_JSON)){
            commonCMD = new byte[]{(byte)0x0d, (byte) 0xc4};
        } else if(mFileName.contains("rtc.json")){
            commonCMD = new byte[]{(byte) 0x0d, (byte) 0xcc};
        } else if(mFileName.contains(SettingsJsonUtils.LOCATION_JSON)){
            commonCMD = new byte[]{(byte) 0x0d, (byte) 0xcd};
        } else if (mFileName.contains(SettingsJsonUtils.USERPROFILE_JSON)){
            commonCMD = new byte[]{(byte)0x0D, (byte) 0xC7};
        } else if(mFileName.contains(SettingsJsonUtils.GEAR_PROFILE_JSON)){
            commonCMD = new byte[]{(byte)0x0D, (byte) 0xC8};
        } else if(mFileName.contains(SettingsJsonUtils.SETTING_JSON)){
            commonCMD = new byte[]{(byte) 0x0D, (byte) 0xC9};
        } else if(mFileName.contains("workout.list")){
            commonCMD = new byte[]{(byte) 0x0D, (byte) 0xD1};
        }
        String strcommonCMD = ArrayUtil.toHex((byte[]) commonCMD);
        Log.i(TAG, "convertTransPacket: strcommonCMD===" + strcommonCMD);
        String currentCMD = CommonUtil.getCurrentPackageCMD(context);
        Log.i(TAG, "convertTransPacket: currentCMD===" + currentCMD);
        CommonUtil.saveCurrentPackageIndex(context,0);
        byte[] sendFileName = new byte[24];
        sendFileName = getBytes(mFileName,24);
        byte[] sendTotalLen = new byte[4];
        sendTotalLen = ArrayUtil.longToBytes2(sendFileName.length + inputBytes.length + sendTotalLen.length);
        byte[] CmdLen = ArrayUtil.intToBytes2(sendFileName.length + inputBytes.length + sendTotalLen.length);
        byte[] final_head = new byte[4];
        final_head = ArrayUtil.byteMerger(commonCMD, CmdLen);
        byte[] total_len = ArrayUtil.byteMerger(sendTotalLen, sendFileName);
        byte[] total_body = ArrayUtil.byteMerger(total_len, inputBytes);
        int totalPacketLen = final_head.length + total_body.length;
        byte[] finalPacket = new byte[totalPacketLen];
        finalPacket = ArrayUtil.byteMerger(final_head, total_body);
        Log.i(TAG, "convertTransPacket: " + ArrayUtil.toHex(finalPacket));
        dataSplit(finalPacket);
        **/
        return true;
    }

    public static byte[] bikeWatchInfo(int id, String params) {
        byte[] data = new byte[28];
        byte[] commonCMD = new byte[]{(byte)0x00, (byte) 0x00 , (byte)0x00, (byte) 0x00};
        if(id == BIKEWATCH_get_personal_info) {
            commonCMD = new byte[]{(byte)0x0D,(byte)0xB7,(byte)0x1C,(byte)0x00};
        } else if (id == BIKEWATCH_get_bicycle_info) {
            commonCMD = new byte[]{(byte)0x0D,(byte)0xB8,(byte)0x1C,(byte)0x00};
        } else if (id == BIKEWATCH_get_settings_info) {
            commonCMD = new byte[]{(byte)0x0D,(byte)0xB9,(byte)0x1C,(byte)0x00};
        } else if (id == BIKEWATCH_GET_PANELS_INFO) {
            commonCMD = new byte[]{(byte) 0x0D,(byte) 0xb4, (byte) 0x1c, (byte) 0x00};
        } else if (id == BIKEWATCH_GET_ROUTE_BOOKS_INFO) {
            commonCMD = new byte[]{(byte) 0x0D,(byte) 0xb6, (byte) 0x1c, (byte) 0x00};
        } else if (id == BIKEWATCH_Reset_settings) {
            commonCMD = new byte[]{(byte) 0x0D,(byte) 0xCA, (byte) 0x1c, (byte) 0x00};
        } else if (id == BIKEWATCH_Reset_device) {
            commonCMD = new byte[]{(byte) 0x0D,(byte) 0xCB, (byte) 0x1c, (byte) 0x00};
        } else if (id == BIKEWATCH_get_track_summary) {
            commonCMD = new byte[]{(byte) 0x0D,(byte) 0xC0, (byte) 0x1c, (byte) 0x00};
        } else if (id == BIKEWATCH_get_track_detail) {
            commonCMD = new byte[]{(byte) 0x0D,(byte) 0xC2, (byte) 0x1c, (byte) 0x00};
        } else if (id == BIKEWATCH_DEL_ALL_track) {
            commonCMD = new byte[]{(byte) 0x0D,(byte) 0xCE, (byte) 0x04, (byte) 0x00};
            data = commonCMD;
            //don't need file name
            return data;
        } else if (id == BIKEWATCH_GET_EMMC_INFO) {
            commonCMD = new byte[]{(byte) 0x0D,(byte) 0xD7, (byte) 0x04, (byte) 0x00};
            data = commonCMD;
            //don't need file name
            return data;
        } else if (id == BIKEWATCH_GET_ICOE_DATA_LEFT_TIME) {
            commonCMD = new byte[]{(byte) 0x0D,(byte) 0xD8, (byte) 0x04, (byte) 0x00};
            data = commonCMD;
            //don't need file name
            return data;
        } else if (id == BIKEWATCH_GET_BB_OFFLINE_LOG_DATA) {
            commonCMD = new byte[]{(byte) 0x0D,(byte) 0xDB, (byte) 0x04, (byte) 0x00};
            byte[] fileName = new byte[64];
            fileName = getBytes(params,64);
            data = ArrayUtil.byteMerger(commonCMD, fileName);
            return data;
        } else if (id == BIKEWATCH_GET_BB_OFFLINE_LOG_LEVEL_INFO) {
            commonCMD = new byte[]{(byte) 0x0D,(byte) 0xDC, (byte) 0x04, (byte) 0x00};
            data = commonCMD;
            //don't need file name
            return data;
        } else if (id == BIKEWATCH_SET_BB_OFFLINE_LOG_LEVEL_INFO) {
            commonCMD = new byte[]{(byte) 0x0D,(byte) 0xF0, (byte) 0x04, (byte) 0x00};
            byte[] logLevel;
            if (params.equals("1")){
                logLevel = new byte[]{(byte) 0x01,(byte) 0x00, (byte) 0x00, (byte) 0x00};
            } else if(params.equals("2")){
                logLevel = new byte[]{(byte) 0x02,(byte) 0x00, (byte) 0x00, (byte) 0x00};
            } else if(params.equals("3")){
                logLevel = new byte[]{(byte) 0x03,(byte) 0x00, (byte) 0x00, (byte) 0x00};
            } else if(params.equals("4")){
                logLevel = new byte[]{(byte) 0x04,(byte) 0x00, (byte) 0x00, (byte) 0x00};
            } else if(params.equals("5")){
                logLevel = new byte[]{(byte) 0x05,(byte) 0x00, (byte) 0x00, (byte) 0x00};
            } else if(params.equals("6")){
                logLevel = new byte[]{(byte) 0x06,(byte) 0x00, (byte) 0x00, (byte) 0x00};
            } else if(params.equals("7")){
                logLevel = new byte[]{(byte) 0x07,(byte) 0x00, (byte) 0x00, (byte) 0x00};
            } else{
                logLevel = new byte[]{(byte) 0x00,(byte) 0x00, (byte) 0x00, (byte) 0x00};
            }
            data = ArrayUtil.byteMerger(commonCMD, logLevel);
            return data;
        } else if (id == BIKEWATCH_GET_BB_OFFLINE_CONFIG_LIST) {
            commonCMD = new byte[]{(byte) 0x0D,(byte) 0xDD, (byte) 0x1c, (byte) 0x00};
        } else if (id == BIKEWATCH_SET_BB_PKG_MTU_MAX) {
            commonCMD = new byte[]{(byte) 0x0D,(byte) 0xD9, (byte) 0x04, (byte) 0x00};
            byte[] flag;
            if (params.equals("1")){
                flag = new byte[]{(byte) 0x01,(byte) 0x00, (byte) 0x00, (byte) 0x00};
            }else{
                flag = new byte[]{(byte) 0x00,(byte) 0x00, (byte) 0x00, (byte) 0x00};
            }
            data = ArrayUtil.byteMerger(commonCMD, flag);
            //don't need file name
            return data;
        }
        byte[] fileName = new byte[24];
        fileName = getBytes(params,24);
        data = ArrayUtil.byteMerger(commonCMD, fileName);

        return data;
    }

    public static boolean bikeWatchDelMultiFiles(int cmdId, List<String> params,String fileName) {
        mDelList.clear();
        mSysId = cmdId;
        mDelList = params;
        mReadType = BB_READ_DEL_FILES_TYPE;
        new readRouteBooksFilesTask().executeTask(fileName);
        /**
        singlePacket.clear();
        byte[] inputBytes;
        try {
            int totalSize = 24*params.size();
            Log.i("TAG", "bikeWatchDelMultiFiles totalSize: --------" + totalSize);
            int dataSize = totalSize;
            inputBytes = new byte[dataSize];
            mFileName = fileName;
            for (int i = 0; i < params.size(); i++){
                Log.i(TAG, "bikeWatchDelMultiFiles fileName" + i + ": " + params.get(i));
                byte[] sendListFileName = new byte[24];
                sendListFileName = getBytes(params.get(i),24);
                System.arraycopy(sendListFileName, 0, inputBytes, i*24, sendListFileName.length);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        Log.i(TAG, "bikeWatchDelMultiFiles: " + inputBytes.length);
        byte[] commonCMD = new byte[]{(byte)0x00, (byte) 0x00};
        if (cmdId == BIKEWATCH_DEL_track){
            commonCMD = new byte[]{(byte)0x0d, (byte) 0xc1};
        } else if (cmdId == BIKEWATCH_DELETE_ROUTEBOOKS_FILES){
            commonCMD = new byte[]{(byte)0x0d, (byte) 0xc3};
        } else if (cmdId == BIKEWATCH_ICOE_PUBLIC_KEY){
            commonCMD = new byte[]{(byte)0x0d, (byte) 0xe6};
        }

        byte[] sendFileName = new byte[24];
        sendFileName = getBytes(mFileName,24);
        byte[] sendTotalLen = new byte[4];
        sendTotalLen = ArrayUtil.longToBytes2(sendFileName.length + inputBytes.length + sendTotalLen.length);
        byte[] CmdLen = ArrayUtil.intToBytes2(sendFileName.length + inputBytes.length + sendTotalLen.length);
        byte[] final_head = new byte[4];
        final_head = ArrayUtil.byteMerger(commonCMD, CmdLen);
        byte[] total_len = ArrayUtil.byteMerger(sendTotalLen, sendFileName);
        byte[] total_body = ArrayUtil.byteMerger(total_len, inputBytes);
        int totalPacketLen = final_head.length + total_body.length;
        byte[] finalPacket = new byte[totalPacketLen];
        finalPacket = ArrayUtil.byteMerger(final_head, total_body);
        dataSplit(finalPacket);
        **/
        return true;
    }

    public static boolean sendRouteBooksFiles(Context context,int id, String params) {
        /**
        singlePacket.clear();
        FileInputStream inputStream = null;
        byte[] inputBytes;
        try {
            inputStream = new FileInputStream(params);
            int totalSize = inputStream.available();
            Log.i("TAG", " totalSize: --------" + totalSize);
            int dataSize = totalSize;
            inputBytes = new byte[dataSize];
            inputStream.read(inputBytes, 0, dataSize);
            inputStream.close();
            Log.i(TAG, "sendRouteBooksFiles: " + inputBytes.length);
            byte[] commonCMD = new byte[]{(byte)0x00, (byte) 0x00};
            if (id == BIKEWATCH_SEND_ROUTEBOOKS_FILES){
                commonCMD = new byte[]{(byte) 0x0d, (byte) 0xd2};
            } else if(id == SYSTEM_TRANS_ELPO_DATA_FILE){
                commonCMD = new byte[]{(byte) 0x0d, (byte) 0xc6};
                SPHelper.putPreference(context, BesSdkConstants.BES_BLE_KEY_ELPO_CMD_ID, SYSTEM_TRANS_ELPO_DATA_FILE);
            }
            String strcommonCMD = ArrayUtil.toHex((byte[]) commonCMD);
            Log.i(TAG, "sendRouteBooksFiles: strcommonCMD===" + strcommonCMD);
            String currentCMD = CommonUtil.getCurrentPackageCMD(context);
            Log.i(TAG, "sendRouteBooksFiles: currentCMD===" + currentCMD);
            byte[] sendFileName = new byte[24];
            String fileName = params.substring(params.lastIndexOf(File.separatorChar) + 1);
            Log.i(TAG, "sendRouteBooksFiles: fileName===" + fileName);
            sendFileName = getBytes(fileName,24);
            byte[] sendTotalLen = new byte[4];
            sendTotalLen = ArrayUtil.longToBytes2(sendFileName.length + inputBytes.length + sendTotalLen.length);
            byte[] CmdLen = ArrayUtil.intToBytes2(sendFileName.length + inputBytes.length + sendTotalLen.length);
            byte[] final_head = new byte[4];
            final_head = ArrayUtil.byteMerger(commonCMD, CmdLen);
            byte[] total_len = ArrayUtil.byteMerger(sendTotalLen, sendFileName);
            byte[] total_body = ArrayUtil.byteMerger(total_len, inputBytes);
            int totalPacketLen = final_head.length + total_body.length;
            byte[] finalPacket = new byte[totalPacketLen];
            finalPacket = ArrayUtil.byteMerger(final_head, total_body);
            //Log.i(TAG, "sendRouteBooksFiles: " + ArrayUtil.toHex(finalPacket));
            dataSplit(finalPacket);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }**/
        mContext = context;
        mSysId = id;
        mReadType = BB_READ_ROUTEBOOKS_TYPE;
        new readRouteBooksFilesTask().executeTask(params);
        return true;
    }

    public static byte[] sendGiveUpTransFiles(Context context) {
        byte[] pkgData;
        try {
            pkgData = new byte[]{(byte) 0x0D,(byte) 0xDF, (byte) 0x1c, (byte) 0x00};
            Log.i(TAG, "sendGiveUpTransFiles: " + ArrayUtil.toHex(pkgData));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return pkgData;
    }

    public static class readRouteBooksFilesTask extends CustomAsyncTask<String, Integer, byte[]> {
        @Override
        protected byte[] doInBackgroundTask(String... strs) {
            singlePacket.clear();
            FileInputStream inputStream = null;
            byte[] inputBytes;
            String filePath = strs[0];
            try {
                if (mReadType == BB_READ_ROUTEBOOKS_TYPE){
                    inputStream = new FileInputStream(filePath);
                    int totalSize = inputStream.available();
                    Log.i("TAG", " totalSize: --------" + totalSize);
                    int dataSize = totalSize;
                    inputBytes = new byte[dataSize];
                    inputStream.read(inputBytes, 0, dataSize);
                    inputStream.close();
                    Log.i(TAG, "sendRouteBooksFiles: " + inputBytes.length);
                    byte[] commonCMD = new byte[]{(byte)0x00, (byte) 0x00};
                    if (mSysId == BIKEWATCH_SEND_ROUTEBOOKS_FILES){
                        commonCMD = new byte[]{(byte) 0x0d, (byte) 0xd2};
                    } else if(mSysId == SYSTEM_TRANS_ELPO_DATA_FILE){
                        commonCMD = new byte[]{(byte) 0x0d, (byte) 0xc6};
                        SPHelper.putPreference(mContext, BesSdkConstants.BES_BLE_KEY_ELPO_CMD_ID, SYSTEM_TRANS_ELPO_DATA_FILE);
                    }
                    String strcommonCMD = ArrayUtil.toHex((byte[]) commonCMD);
                    Log.i(TAG, "sendRouteBooksFiles: strcommonCMD===" + strcommonCMD);
                    String currentCMD = CommonUtil.getCurrentPackageCMD(mContext);
                    Log.i(TAG, "sendRouteBooksFiles: currentCMD===" + currentCMD);
                    byte[] sendFileName = new byte[24];
                    String fileName = filePath.substring(filePath.lastIndexOf(File.separatorChar) + 1);
                    Log.i(TAG, "sendRouteBooksFiles: fileName===" + fileName);
                    sendFileName = getBytes(fileName,24);
                    byte[] sendTotalLen = new byte[4];
                    sendTotalLen = ArrayUtil.longToBytes2(sendFileName.length + inputBytes.length + sendTotalLen.length);
                    byte[] CmdLen = ArrayUtil.intToBytes2(sendFileName.length + inputBytes.length + sendTotalLen.length);
                    byte[] final_head = new byte[4];
                    final_head = ArrayUtil.byteMerger(commonCMD, CmdLen);
                    byte[] total_len = ArrayUtil.byteMerger(sendTotalLen, sendFileName);
                    byte[] total_body = ArrayUtil.byteMerger(total_len, inputBytes);
                    int totalPacketLen = final_head.length + total_body.length;
                    byte[] finalPacket = new byte[totalPacketLen];
                    finalPacket = ArrayUtil.byteMerger(final_head, total_body);
                    //Log.i(TAG, "sendRouteBooksFiles: " + ArrayUtil.toHex(finalPacket));
                    //dataSplit(finalPacket);
                    return finalPacket;
                }else if(mReadType == BB_READ_CONFIG_INFO_TYPE){
                    inputStream = new FileInputStream(filePath);
                    int totalSize = inputStream.available();
                    Log.i("TAG", " totalSize: --------" + totalSize);
                    int dataSize = totalSize;
                    inputBytes = new byte[dataSize];
                    inputStream.read(inputBytes, 0, dataSize);
                    inputStream.close();
                    Log.i(TAG, "convertTransPacket: " + inputBytes.length);
                    byte[] commonCMD = new byte[]{(byte)0x00, (byte) 0x00};
                    if (mFileName.contains(SettingsJsonUtils.ROUTE_BOOKS_JSON)){
                        commonCMD = new byte[]{(byte)0x0d, (byte) 0xc5};
                    } else if(mFileName.contains(SettingsJsonUtils.PANEL_JSON)){
                        commonCMD = new byte[]{(byte)0x0d, (byte) 0xc4};
                    } else if(mFileName.contains(SettingsJsonUtils.WIFI_OTA_JSON)){
                        commonCMD = new byte[]{(byte) 0x0d, (byte) 0xcc};
                    } else if(mFileName.contains(SettingsJsonUtils.LOCATION_JSON)){
                        commonCMD = new byte[]{(byte) 0x0d, (byte) 0xcd};
                    } else if (mFileName.contains(SettingsJsonUtils.USERPROFILE_JSON)){
                        commonCMD = new byte[]{(byte)0x0D, (byte) 0xC7};
                    } else if(mFileName.contains(SettingsJsonUtils.GEAR_PROFILE_JSON)){
                        commonCMD = new byte[]{(byte)0x0D, (byte) 0xC8};
                    } else if(mFileName.contains(SettingsJsonUtils.SETTING_JSON)){
                        commonCMD = new byte[]{(byte) 0x0D, (byte) 0xC9};
                    } else if(mFileName.contains("workout.list")){
                        commonCMD = new byte[]{(byte) 0x0D, (byte) 0xD1};
                    }
                    String strcommonCMD = ArrayUtil.toHex((byte[]) commonCMD);
                    Log.i(TAG, "convertTransPacket: strcommonCMD===" + strcommonCMD);
                    String currentCMD = CommonUtil.getCurrentPackageCMD(mContext);
                    Log.i(TAG, "convertTransPacket: currentCMD===" + currentCMD);
                    CommonUtil.saveCurrentPackageIndex(mContext,0);
                    byte[] sendFileName = new byte[24];
                    sendFileName = getBytes(mFileName,24);
                    byte[] sendTotalLen = new byte[4];
                    sendTotalLen = ArrayUtil.longToBytes2(sendFileName.length + inputBytes.length + sendTotalLen.length);
                    byte[] CmdLen = ArrayUtil.intToBytes2(sendFileName.length + inputBytes.length + sendTotalLen.length);
                    byte[] final_head = new byte[4];
                    final_head = ArrayUtil.byteMerger(commonCMD, CmdLen);
                    byte[] total_len = ArrayUtil.byteMerger(sendTotalLen, sendFileName);
                    byte[] total_body = ArrayUtil.byteMerger(total_len, inputBytes);
                    int totalPacketLen = final_head.length + total_body.length;
                    byte[] finalPacket = new byte[totalPacketLen];
                    finalPacket = ArrayUtil.byteMerger(final_head, total_body);
                    Log.i(TAG, "convertTransPacket: " + ArrayUtil.toHex(finalPacket));
                    //dataSplit(finalPacket);
                    return finalPacket;
                }else if(mReadType == BB_READ_DEL_FILES_TYPE){
                    byte[] inputDelBytes;
                    try {
                        if (mSysId == BIKEWATCH_ICOE_PUBLIC_KEY){
                            int totalDelSize = mDelList.get(0).length();
                            Log.i("TAG", "bikeWatchDelMultiFiles totalSize: --------" + totalDelSize);
                            int dataDelSize = totalDelSize;
                            inputDelBytes = new byte[dataDelSize];
                            byte[] sendListFileName = new byte[dataDelSize];
                            sendListFileName = getBytes(mDelList.get(0),dataDelSize);
                            System.arraycopy(sendListFileName, 0, inputDelBytes, 0, sendListFileName.length);
                        } else{
                            int totalDelSize = 24*mDelList.size();
                            Log.i("TAG", "bikeWatchDelMultiFiles totalSize: --------" + totalDelSize);
                            int dataDelSize = totalDelSize;
                            inputDelBytes = new byte[dataDelSize];
                            for (int i = 0; i < mDelList.size(); i++){
                                Log.i(TAG, "bikeWatchDelMultiFiles fileName" + i + ": " + mDelList.get(i));
                                byte[] sendListFileName = new byte[24];
                                sendListFileName = getBytes(mDelList.get(i),24);
                                System.arraycopy(sendListFileName, 0, inputDelBytes, i*24, sendListFileName.length);
                            }
                        }
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    Log.i(TAG, "bikeWatchDelMultiFiles: " + inputDelBytes.length);
                    byte[] commonCMD = new byte[]{(byte)0x00, (byte) 0x00};
                    if (mSysId == BIKEWATCH_DEL_track){
                        commonCMD = new byte[]{(byte)0x0d, (byte) 0xc1};
                    } else if (mSysId == BIKEWATCH_DELETE_ROUTEBOOKS_FILES){
                        commonCMD = new byte[]{(byte)0x0d, (byte) 0xc3};
                    } else if (mSysId == BIKEWATCH_ICOE_PUBLIC_KEY){
                        commonCMD = new byte[]{(byte)0x0d, (byte) 0xe6};
                    }

                    byte[] sendFileName = new byte[24];
                    sendFileName = getBytes(filePath,24);
                    byte[] sendTotalLen = new byte[4];
                    sendTotalLen = ArrayUtil.longToBytes2(sendFileName.length + inputDelBytes.length + sendTotalLen.length);
                    byte[] CmdLen = ArrayUtil.intToBytes2(sendFileName.length + inputDelBytes.length + sendTotalLen.length);
                    byte[] final_head = new byte[4];
                    final_head = ArrayUtil.byteMerger(commonCMD, CmdLen);
                    byte[] total_len = ArrayUtil.byteMerger(sendTotalLen, sendFileName);
                    byte[] total_body = ArrayUtil.byteMerger(total_len, inputDelBytes);
                    int totalPacketLen = final_head.length + total_body.length;
                    byte[] finalPacket = new byte[totalPacketLen];
                    finalPacket = ArrayUtil.byteMerger(final_head, total_body);
                    //dataSplit(finalPacket);
                    return finalPacket;
                }
                return null;
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            int progress = values[0];
            Log.i(TAG, progress + "%" + "\n");
        }

        @Override
        protected void onPostExecute(byte[] finalData) {
            Log.i(TAG, "onPostExecute: finalData");
            if (finalData != null) {
                dataSplit(finalData);
                Log.i(TAG, "splitFileContent done! ready to" + "\n");
                ProtocolPresenter.getInstance().sendWatchDialOTA(singlePacket,ProtocolService.mWatchDialSendPacket);
            }
        }
    }
}